<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php ob_start();?>
<?php 
$root = $_SERVER['DOCUMENT_ROOT'];
include($root.'/standart/head.php');
include($root.'/standart/dateHeader.php');
include($root.'/standart/dbconnect.php');
setlocale(LC_CTYPE, 'de_DE.UTF8');

function strtouppertr($metin){
	//return str_replace('Ş','&#350;',mb_convert_case(str_replace('i','İ',$metin), MB_CASE_UPPER, "UTF-8"));
	return mb_convert_case(str_replace('i','İ',$metin), MB_CASE_UPPER, "UTF-8");
}
?>
<?php
	$orderId = $_GET['orderId'];
	$db = connect();
	$stmt ="SELECT ORDER_DATE, TOTAL_AMOUNT, PAYMENT_TYPE, NOTES, GEVEZE_USER.NAME, GEVEZE_USER.SURNAME, SHIPPING_ADDRESS, RELATED_FIRM, CANCEL
			FROM ORDERS, GEVEZE_USER
			WHERE
				ORDERS.USER_ID = GEVEZE_USER.ID
				AND ORDERS.ID = $orderId";
		$res = $db->query($stmt) or die($stmt."<br/><br/>".mysql_error());
		if($row = $res->fetch_assoc()){
			$name = $row['NAME'].' '.$row['SURNAME'] ; 
			$firmName = '';
			if($row['RELATED_FIRM'] != null){
				$stmtFirm ="SELECT NAME
						FROM GEVEZE_USER
						WHERE ID = ".$row['RELATED_FIRM'];
				$resFirm = $db->query($stmtFirm) or die($stmt."<br/><br/>".mysql_error());
				if($rowFirm = $resFirm->fetch_assoc()){
					$firmName = $rowFirm['NAME'];
				}
			}

	?>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <style type="text/css">
  @page {  margin: 0px;
  margin-top:-10px; }
           html
           {
               font-family: "Arial Unicode MS";
               height: 100%;
           }
          <?php if($row['CANCEL'] == 1){?>
          #myelement
			{
				position: relative;
				overflow: hidden;
			}
          
          #myelement:before
			{
				content: "";
				position: absolute;
				width: 200%;
				height: 200%;
				top: -50%;
				left: -50%;
				z-index: -1;
				
				background: url('../images/cancel.png') repeat;
				
				-webkit-transform: rotate(300deg); 
				-moz-transform: rotate(300deg); 
				-ms-transform: rotate(300deg); 
				-o-transform: rotate(300deg); 
				transform: rotate(300deg); 
				filter:alpha(opacity=50);
			    filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0.5);
			    opacity:.50;
			}
			<?php }?>
  </style>
</head>
<body style="height: 100%; margin: 0px;" >
    <div style="width: 100%; height: 100%;">
		<table id="myelement" style="border: none; width: 270px;" >
			<tr>
				<td colspan="2"><img src="http://www.gevezecafe.com/images/logo-gevezecafeBW.png" alt="img" width="100%" height="100%"></img></td>
			</tr>
			<tr>
				<td colspan="2" style="font-size: 12px; font-weight: bold; vertical-align: top; text-align: center;"> <?php echo strtouppertr($name);?></td>
			</tr>
			<?php if($firmName <> ''){?>
				<tr>
					<td colspan="2" style="font-size: 12px; font-weight: bold; vertical-align: top; text-align: center;"> <?php echo strtouppertr($firmName);?></td>
				</tr>
			<?php }?>
			<?php 
			if($row['SHIPPING_ADDRESS'] != null && $row['SHIPPING_ADDRESS'] <> ''){
				$stmtAdd ="SELECT ADDRESS_DEFINITION, ADDRESS_1, ADDRESS_2, COUNTY_NAME, IFNULL(PHONE, CELL_PHONE) AS PHONE
					FROM ADDRESS LEFT JOIN COUNTY_LOOKUP ON COUNTY_LOOKUP.ID = ADDRESS.COUNTY_ID
					WHERE ADDRESS.ID = ".$row['SHIPPING_ADDRESS'];
				$resAdd = $db->query($stmtAdd) or die($stmt."<br/><br/>".mysql_error());
				if($rowAdd = $resAdd->fetch_assoc()){
						?>
						<tr>
							<td colspan="2"> <?php echo strtouppertr($rowAdd['ADDRESS_DEFINITION']);?></td>
							
						</tr>
						<tr>
							<td colspan="2" style="border-bottom: 2px solid; border-bottom-style: dashed;"> <?php echo strtouppertr($rowAdd['ADDRESS_1'].' '.$rowAdd['ADDRESS_2'].' '.$rowAdd['COUNTY_NAME']);?></td>
						</tr>
						
						<?php 
				}else{
					?>
					<tr>
						<td colspan="2" style="border-bottom: 2px solid; border-bottom-style: dashed; text-align: center; font-size: 12px; font-weight: bold; height: 20px; vertical-align: bottom;"> MASA SİPARİŞİ</td>
					</tr>
					<?php 
				}
			}
			?>
			<tr style="height: 20px; font-size:12px; vertical-align: bottom;" >
				<td style="text-align: left;"> SİP. TAR. : <?php echo date("d/m/Y H:i",strtotime($row['ORDER_DATE']));?></td>
				<td style="text-align: right;"> SİP. NO : <?php echo $orderId;?></td>
			</tr>
			<tr>
				<td colspan="2" style="border-bottom: 2px solid; border-bottom-style: dashed; text-align: left; font-size:12px;"> AÇIKLAMA : <?php echo $row['NOTES'];?></td>
			</tr>
			<tr>
				<td colspan="2">
					<table style="border: none; margin-top: 6px; width: 100%;">
					<?php 
						$stmtItem ="SELECT QUANTITY, ITEM_NOTE, PRODUCT_NAME, UNIT
							FROM ORDER_ITEMS, MENU
							WHERE
								MENU_ID = MENU.ID
								AND ORDER_ID = $orderId";
						$resItem = $db->query($stmtItem) or die($stmt."<br/><br/>".mysql_error());
						while ($rowItem = $resItem->fetch_assoc()){
							?>
								<tr>
									<td style="text-align: right; font-size: 12px; font-weight: bold; "><?php echo $rowItem['QUANTITY'];?></td>
									<td style="text-align: right; font-size: 12px; font-weight: bold; "><?php echo $rowItem['UNIT'];?></td>
									<td style="font-size: 12px; font-weight: bold; "><?php echo $rowItem['PRODUCT_NAME'];?></td>
								</tr>
								<tr>
									<td colspan="3" style="border-bottom: 1px solid; border-bottom-style: dotted;"><?php echo ($rowItem['ITEM_NOTE']);?></td>
								</tr>
							<?php 
						}
					?>
					</table>
				</td>
			</tr>
			<tr>
				<td colspan="2" style="border-bottom: 2px solid; border-bottom-style: outset;"></td>
			</tr>
			<tr>
				<td colspan="2" style="font-size: 12px; font-weight: bold; height: 20px; text-align: right;">TOPLAM TUTAR : <?php echo $row['TOTAL_AMOUNT'];?></td>
			</tr>
		</table>
    </div>
    
</body>
<?php 
    	}
	    $res->close();
	    disconnect($db);
    ?>
</html>


<?php ob_end_flush(); ?>